package com.ruoyi.cloudpc.controller;

import com.ruoyi.cloudpc.domain.CloudAfterSale;
import com.ruoyi.cloudpc.mapper.CloudOrderMapper;
import com.ruoyi.cloudpc.service.ICloudAfterSaleService;
import com.ruoyi.cloudpc.service.ICloudOrderService;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.core.page.TableDataInfo;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.common.utils.poi.ExcelUtil;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServletResponse;
import java.util.List;

/**
 * 售后Controller
 *
 * @author Ten
 * @date 2025-09-13
 */
@RestController
@RequestMapping("/cloudpc/sale")
public class CloudAfterSaleController extends BaseController {
    @Autowired
    private ICloudAfterSaleService cloudAfterSaleService;

    /**
     * 查询售后列表
     */
//    @PreAuthorize("@ss.hasPermi('cloudpc:sale:list')")
    @GetMapping("/list")
    public TableDataInfo list(CloudAfterSale cloudAfterSale) {
        startPage();
        List<CloudAfterSale> list = cloudAfterSaleService.selectCloudAfterSaleList(cloudAfterSale);
        return getDataTable(list);
    }

    /**
     * 导出售后列表
     */
//    @PreAuthorize("@ss.hasPermi('cloudpc:sale:export')")
    @Log(title = "售后", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, CloudAfterSale cloudAfterSale) {
        List<CloudAfterSale> list = cloudAfterSaleService.selectCloudAfterSaleList(cloudAfterSale);
        ExcelUtil<CloudAfterSale> util = new ExcelUtil<CloudAfterSale>(CloudAfterSale.class);
        util.exportExcel(response, list, "售后数据");
    }

    /**
     * 获取售后详细信息
     */
//    @PreAuthorize("@ss.hasPermi('cloudpc:sale:query')")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id) {
        return success(cloudAfterSaleService.selectCloudAfterSaleById(id));
    }

    /**
     * 新增售后
     */
//    @PreAuthorize("@ss.hasPermi('cloudpc:sale:add')")
    @Log(title = "售后", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody CloudAfterSale cloudAfterSale) {
        return toAjax(cloudAfterSaleService.insertCloudAfterSale(cloudAfterSale));
    }

    /**
     * 修改售后
     */
//    @PreAuthorize("@ss.hasPermi('cloudpc:sale:edit')")
    @Log(title = "售后处理", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody CloudAfterSale cloudAfterSale) {
        // 将售后状态标记为已处理
        cloudAfterSale.setStatus("1");
        return toAjax(cloudAfterSaleService.updateCloudAfterSale(cloudAfterSale));
    }

    /**
     * 删除售后
     */
//    @PreAuthorize("@ss.hasPermi('cloudpc:sale:remove')")
    @Log(title = "售后", businessType = BusinessType.DELETE)
    @DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids) {
        return toAjax(cloudAfterSaleService.deleteCloudAfterSaleByIds(ids));
    }
}
